package com.appkubes.mall.admin.application.admin.login;

import com.appkubes.cloud.config.params.paramValid.ParamValid;
import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.admin.admin.service.AdminService;
import com.appkubes.mall.admin.application.user.user.entity.vo.LoginByTelVO;
import com.appkubes.mall.core.entity.MallAdmin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: Rongjie
 * @Date: 2020/1/12 16:13
 * @Description: 支持多种登录方式
 */
@Api(description = "用户登录")
@RestController
@RequestMapping("/admin/login")
public class AdminLoginController {
    @Resource
    AdminService adminService;

    @ApiOperation("使用手机号登录")
    @PostMapping("/loginByTel")
    public Response<MallAdmin> loginByTel(@ParamValid LoginByTelVO loginByTelVO) {
        MallAdmin admin = adminService.getAdminDao().selectByUserName(loginByTelVO.getAppKey(), loginByTelVO.getTel());
        if (loginByTelVO.getTel().equalsIgnoreCase(admin.getUserName())
                && loginByTelVO.getPassword().equalsIgnoreCase(admin.getPassword())) {
            return Response.success(admin);
        }
        return Response.error("账号密码错误");
    }
}
